Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Services
Imports System.Runtime.Remoting.Messaging


Public Class MyTrackingHandler
    Implements ITrackingHandler

    Public Sub DisconnectedObject(ByVal obj As Object) Implements System.Runtime.Remoting.Services.ITrackingHandler.DisconnectedObject

    End Sub

    Public Sub MarshaledObject(ByVal obj As Object, ByVal [or] As System.Runtime.Remoting.ObjRef) Implements System.Runtime.Remoting.Services.ITrackingHandler.MarshaledObject
        Dim ObservedIP As Object = CallContext.GetData("ObservedIP")
        If ObservedIP Is Nothing Then
            Return
        End If

        If [or].ChannelInfo Is Nothing Then
            Return
        End If

        Dim strAddress As String = CType(ObservedIP, String)

        For I As Integer = [or].ChannelInfo.ChannelData.GetLowerBound(0) To [or].ChannelInfo.ChannelData.GetUpperBound(0) - 1
            If TypeOf [or].ChannelInfo.ChannelData(I) Is ChannelDataStore Then
                For Each uri As String In CType([or].ChannelInfo.ChannelData(I), ChannelDataStore).ChannelUris
                    Dim nOffset As Integer = uri.IndexOf("//") + 2
                    Dim strNewUri As String = uri.Substring(0, nOffset)
                    strNewUri += strAddress
                    nOffset = uri.IndexOf(":", nOffset)
                    strNewUri += uri.Substring(nOffset, uri.Length - nOffset)
                    Dim strArray(0) As String
                    strArray(0) = strNewUri
                    Dim cds As New ChannelDataStore(strArray)
                    [or].ChannelInfo.ChannelData(I) = cds
                Next
            End If
        Next
    End Sub

    Public Sub UnmarshaledObject(ByVal obj As Object, ByVal [or] As System.Runtime.Remoting.ObjRef) Implements System.Runtime.Remoting.Services.ITrackingHandler.UnmarshaledObject

    End Sub
End Class
